package com.demo.util;

import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo1 {

    public static void main(String[] args) {
        //这将创建一个核心池大小为5，最大池大小为10，保持活动时间为60秒的执行器。然后，它将向执行器提交20个任务，并在所有任务完成后关闭它
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
        for (int i = 0; i < 20; i++) {
            int finalI = i;
            executor.execute(new Runnable() {
                public void run() {
                    // 并行运行的代码
                    System.out.println(finalI);
                }
            });
        }
        executor.shutdown();
    }




}
